<?php
namespace Modules\Admin\Http\Controllers;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Modules\Admin\Entities\Chatgroup;
use Modules\Admin\Http\Requests\ChatgroupRequest;
class ChatgroupController extends Controller
{
    //显示列表
    public function index()
    {
        $data = Chatgroup::paginate(10);
        return view('admin::chatgroup.index', compact('data'));
    }

    //创建视图
    public function create(Chatgroup $chatgroup)
    {
        return view('admin::chatgroup.create',compact('chatgroup'));
    }

    //保存数据
    public function store(ChatgroupRequest $request,Chatgroup $chatgroup)
    {
        $chatgroup->fill($request->all());
        $chatgroup->save();

        return redirect('/admin/chatgroup')->with('success', '保存成功');
    }

    //显示记录
    public function show(Chatgroup $field)
    {
        return view('admin::chatgroup.show', compact('field'));
    }

    //编辑视图
    public function edit(Chatgroup $chatgroup)
    {
        return view('admin::chatgroup.edit', compact('chatgroup'));
    }

    //更新数据
    public function update(ChatgroupRequest $request, Chatgroup $chatgroup)
    {
        $chatgroup->update($request->all());
        return redirect('/admin/chatgroup')->with('success','更新成功');
    }

    //删除模型
    public function destroy(Chatgroup $chatgroup)
    {
        $chatgroup->delete();
        return redirect('admin/chatgroup')->with('success','删除成功');
    }
}
